<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/global.css">
    <link rel="stylesheet" href="css/login.css">
    <script type="text/javascript" src="js/login.js"></script>
    <link rel="icon" href="./images/icon.png">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
    <title>登录</title>
    <script>
        function submits() {
            //获取name和pwd的值
            var name = document.querySelector('#userName').value
            var pwd = document.querySelector('#pwd').value
            //用dom操作方式或者Jquery
            $.ajax({
                url: 'http://localhost:3000/api/login',
                type: 'post',
                data: {userName: name, userPwd: pwd },
                success: function (res) {
                    console.log(res)
                    if (res.message == 'ok') {
                        alert('登陆成功！')
                        //信息存储到本地存储
                        localStorage.setItem('currentUser',JSON.stringify(res.data))
                        location.href = 'http://localhost:5502/9-24获取用户信息测试.html'
                    } else {
                        alert('登录失败！')
                    }
                }
            })
        }
    </script>
</head>

<body>
    <div class="login">
        <div class="container">
            <h1>用户登录</h1>
            <form>
                <br>
                <label for="username">用户名</label><br>
                <input type="text" name="username" id="userName" class="input" value="" placeholder="用户名admin"><br>
                <label for="pwd">密码</label><br>
                <input type="password" name="" id="pwd" class="input" value="" placeholder="密码admin">
                <div class="checkbox">
                    <input type="checkbox" name="" id="remPwd">
                    <span>记住密码</span>
                </div>
                <input type="button"  value="开始登录" class="submit" onclick="submits()">
                <!-- <input type="button" value="同意以上协议并注册" class="submit" onclick="register()"><br> -->
                <br>
                <a href="index.html" class="left">返回首页</a>
                <a href="register.html" class="right">注册账号</a>
            </form>
        </div>
    </div>
</body>

</html>